#ifndef DRM_PLANE_DRV_H
#define DRM_PLANE_DRV_H

#include <stdint.h>
#include <xf86drm.h>
#include <xf86drmMode.h>
#include <drm_fourcc.h>
#include <libkms.h>
#ifdef __cplusplus
extern "C" {
#endif

#define DRM_CARD "/dev/dri/card0"

struct buffer_object {
    int fd;
    uint8_t *vaddr;

    uint32_t pitch;
    uint32_t handle;
    uint32_t size;

    uint32_t fb_id;
};

struct drm_buffers{
    int32_t width, height;
    int buf_num;
    unsigned int fourcc;
   struct buffer_object *bo;
};

struct plane_arg {
    int fd;
    uint32_t plane_id;  /* the id of plane to use */
    uint32_t crtc_id;  /* the id of CRTC to bind to */
    int32_t x, y;
    uint32_t w, h;
    double scale;
    unsigned int fb_id;
    unsigned int old_fb_id;
    int buf_num;
    struct buffer_object *bo;
    struct buffer_object *old_bo;
    unsigned int fourcc;
};
int drm_print();
int drm_crtc_id_init();
int drm_alpha_init();
int drm_set_plane_prop(unsigned int plane_id, const char *prop_name, int prop_val);
int init_plane(struct plane_arg *plane,uint32_t plane_id, uint32_t width, uint32_t height,int32_t x,int32_t y,unsigned int fourcc);
int plane_destroy(struct plane_arg *plane);
int bo_create_dumb(int fd,struct buffer_object *bo, unsigned int width, unsigned int height, unsigned int bpp);
void bo_create(int fd,struct buffer_object *bo, unsigned int format,
      unsigned int width, unsigned int height,
      unsigned int handles[4], unsigned int pitches[4],
      unsigned int offsets[4]);
void bo_destroy(struct buffer_object *bo);
int set_plane(struct plane_arg *p);
int plane_bind_buf(int fd, struct plane_arg *p,struct buffer_object plane_bo);

int init_drm_bufs(int fd,struct drm_buffers *drm_bufs,int32_t width,int32_t height,int buf_num,unsigned int fourcc);
void drm_bufs_destroy(struct buffer_object *bufs,int buf_num);
int plane_cpy(struct plane_arg *p,void * addr);
int switch_plane_buffer(struct plane_arg *p,unsigned char buf_count);

#ifdef __cplusplus
}
#endif


#endif // V4L2_START_H
